﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SLAU
{
    /// <summary>
    /// Custom vector class
    /// </summary>
    public class Vector
    {
        double[] elements;

        /// <summary>
        /// Elements of vector
        /// </summary>
        public double[] Elements
        {
            get
            {
                return this.elements;
            }
            set
            {
                if (value == null)
                {
                    throw new NullReferenceException();
                }
                this.elements = value;
            }
        }

        /// <summary>
        /// Length of vector
        /// </summary>
        public int Length
        {
            get
            {
                return this.elements.Length;
            }
        }

        public Vector()
        {
            this.elements=new double[1];
        }

        public Vector(int capacity)
        {
            if (capacity <= 0)
            {
                throw new ArgumentException();
            }
            this.elements = new double[capacity];
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="elements">Elements of new vector</param>
        public Vector(double[] elements)
        {
            this.Elements = elements;
        }

        /// <summary>
        /// Copy constuctor
        /// </summary>
        /// <param name="source">Source vector</param>
        public Vector(Vector source)
        {
            if (source == null)
            {
                throw new NullReferenceException();
            }
            if (source.Length == 0)
            {
                throw new ArgumentException();
            }

            this.elements=new double[source.Length];

            for (int i = 0; i < this.Length; i++)
            {
                this.elements[i] = source.elements[i];
            }
        }

        /// <summary>
        /// Indexer
        /// </summary>
        /// <param name="index">Index</param>
        /// <returns></returns>
        public double this[int index]
        {
            get
            {
                if (index < 0 || index >= this.Length)
                {
                    throw new IndexOutOfRangeException();
                }
                return this.elements[index];
            }
            set
            {
                if (index < 0 || index >= this.Length)
                {
                    throw new IndexOutOfRangeException();
                }
                this.elements[index] = value;
            }
        }

        /// <summary>
        /// Copy method
        /// </summary>
        /// <param name="destination">Destination vector</param>
        public void CopyTo(Vector destination)
        {
            destination.elements = new double[this.Length];
            for (int i = 0; i < this.Length; i++)
            {
                destination.elements[i] = this.elements[i];
            }
        }
    }
}
